package qdu.edu.com.fushanf4.service.count.usertype.sort.topn;

import org.apache.hadoop.mapreduce.Job;
import qdu.edu.com.fushanf4.service.sort.IntWritableSortDriver;
import qdu.edu.com.fushanf4.service.sort.topn.IntWritableSortAndTopNReducer;
import qdu.edu.com.fushanf4.utils.ConfigurationUtil;
import qdu.edu.com.fushanf4.utils.DriverUtil;

import java.io.IOException;

public class CharacterOfProductDescriptionSortAndTopNDriver extends DriverUtil {
    public static void main(String[] args) throws IOException {
        CharacterOfProductDescriptionSortAndTopNDriver characterOfProductDescriptionSortAndTopNDriver = new CharacterOfProductDescriptionSortAndTopNDriver();
        characterOfProductDescriptionSortAndTopNDriver.run(args);
    }

    @Override
    public Job runJob(String[] path) throws IOException {
        Job job = ConfigurationUtil.getJob();

        // 设置TopN
        assert path.length == 3;
        job.getConfiguration().set("topN", path[2]);

        // 设置map,reduce
        IntWritableSortDriver.sortMapperReducerJobConfig(job);
        job.setReducerClass(IntWritableSortAndTopNReducer.class);

        assert ConfigurationUtil.setPathAndRunJob(new String[]{path[0], path[1]},job);
        return job;
    }
}
